package com.ruoyi.buss.utils;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.xfire.client.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * 身份证联网核查服务
 */
@Component
public class IdCardNetVerify {

    //private static final Logger logger = Logger.getLogger(IdCardNetVerify.class);
    private static final Logger logger = LoggerFactory.getLogger(IdCardNetVerify.class);

    // 联网核查接口地址
    private static String verifyUrl = "http://32.172.33.13:80/lsyd-service/idCardService.ws?wsdl";


    /**
     * 联网核查接口调用
     * @param idCard
     * @param name
     * @return
     */
    public static String verify(String idCard, String name) {
        Client client;
        try {
            client = new Client(new URL(verifyUrl));
            client.setTimeout(240000);
            Object[] responseData = client.invoke("verify", new Object[] { idCard, name });
            return (String) responseData[0];
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return null;
    }

    public static void main(String[] args) {
        String str = "[\"个体户\",\"普通农户\"]";
        JSONArray array=JSON.parseArray(str);
        System.out.println(array);

        List<String> labelList = JSONObject.parseArray(array.toJSONString(), String.class);

//        String[] strings =str.split(",");
//        Collections.addAll(labelList,strings);
//        List<String> strings = Arrays.asList(str);
//        Collections.addAll(labelList,str);
        System.out.println(labelList);
        System.out.println(labelList.size());

        for (int i=0;i<labelList.size();i++){
            System.out.println(labelList.get(i));
        }

//        String jsonStr = IdCardNetVerify.verify("34100319931202081X", "丁凯");
//        if (StringUtils.isNotEmpty(jsonStr)) {
//            JSONObject json = JSON.parseObject(jsonStr);
//            String code = json.getString("code");
//            if ("00".equals(code)) {
//                String idCardNo = json.getString("idCard");
//                String name = json.getString("name");
//                String res = json.getString("msg");
//                String photo = json.getString("photo");
//                System.out.println("返回状态码：" + code);
//                System.out.println("身份证号码:" + idCardNo);
//                System.out.println("用户姓名:" + name);
//                System.out.println("提示信息:" + res);
//                System.out.println("头像:" + photo);
//
//                Base64ImageHelper.generateImage(photo, "D://", "34100319931202081X.jpg");
//            } else {
//                System.out.println(json.getString("msg"));
//            }
//        }
    }

}

